Skip to content

Comments

py: implement input#252

Open
aisk wants to merge 6 commits intogo-python:mainfrom
aisk:input
Open

py: implement input#252
aisk wants to merge 6 commits intogo-python:mainfrom
aisk:input

Conversation

@aisk
Copy link
Contributor

@aisk aisk commented Feb 7, 2026

Since liner takes over control of stdin in the REPL, an InputHook is added and registered in REPL mode, which will use liner to get the input instead of reading from stdin directly.

Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR.

I have a couple of comments, see below.
also, it'd be great to add tests for this.

thanks again.

Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple of nitpicks.

return o.readResult(b)
}

func (o *File) Readline() (Object, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps add a test for this new method in tests/file.py ?

}, 0, "flush() -> Flush the write buffers of the stream if applicable. This does nothing for read-only and non-blocking streams.")
FileType.Dict["readline"] = MustNewMethod("readline", func(self Object) (Object, error) {
return self.(*File).Readline()
}, 0, "readline() -> next line from the file, as a string.\n\nRetains newline. A non-empty string returned implies that readline() returned\na line, empty string returned implies that EOF is reached.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the actual documentation from CPython reads:

readline(size=-1, /)

Read and return one line from the stream. If size is specified, at most size bytes will be read.

    The line terminator is always b'\n' for binary files; for text files, the newline argument to open can be used to select the line terminator(s) recognized.

https://docs.python.org/3/library/io.html#io.IOBase.readline

well, newline isn't implemented (yet) on stdlib.open but...

(perhaps we could also fix the readline signature to match the CPython one, w/o actually implementing the size thing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants